package com.yulongtian.oneProblemEveryDay.month202211.day20221103;

/**
 * https://leetcode.cn/problems/maximum-repeating-substring/
 * OK
 *
 * @author yulongTian
 * @create 2022-11-03 13:31
 */
public class Test01 {
    public static void main(String[] args) {
        System.out.println(maxRepeating("ababc", "ba"));
    }


    public static int maxRepeating(String sequence, String word) {
        int res = 0;
        char[] chars = sequence.toCharArray();
        char[] words = word.toCharArray();
        int chars_len = sequence.length();
        int word_len = word.length();
        if (word_len > chars_len) {
            return 0;
        }
        int temp_res = 0;
        int start_index = 0;
        for (int i = 0; i < chars_len - word_len + 1; i++) {
            boolean is_same = true;
            int j = 0;
            for (; j < word_len; j++) {
                if (chars[i + j] != words[j]) {
                    is_same = false;
                    break;
                }
            }
            if (is_same) {
                temp_res++;
                i += word_len - 1;
            } else {
                res = Math.max(res, temp_res);
                temp_res = 0;
                i = start_index;
                start_index++;
            }
        }
        res = Math.max(res, temp_res);
        return res;

    }

}
